/**
 * JAVACC DEMO 1.0
 * @copy right dwusoft company All rights reserved. 
 * @Package com.apache.info.service.plugins  
 */
package com.apache.info.service.plugins;

import java.util.Map;

import com.apache.api.vo.ParamsVo;
import com.apache.cache.util.Validator;
import com.apache.info.entity.PubInfoStatistics;
import com.apache.info.manager.InfoReleaseManager;
import com.apache.info.manager.PubInfoStatisticsManager;

/**
 * description:  动态插入信息
 * @author Hou Dayu 创建时间：2015-8-29  
 * @Copyright(c)2014:北京--软件技术有限公司
 */
public class InsertDynamicInfoPluginImpl extends AbstractInfoReleasePlugin {

	private InfoReleaseManager InfoReleaseManager;
	private PubInfoStatisticsManager pubInfoStatisticsManager;

	/**
	 * TODO 动态插入信息插件实现.  
	 * @see com.apache.info.service.plugins.AbstractInfoReleasePlugin#doInvoke(com.apache.api.vo.ParamsVo)  
	 */
	protected Object doInvoke(ParamsVo vo) {
		String mark = InfoReleaseManager.saveInfo(vo);
		if ("true".equals(mark) && "true".equals(String.valueOf(vo.getParams("flagInfoStatistics")))) {//添加统计信息
			Map map = vo.getParams();
			ParamsVo pvo = new ParamsVo();
			if (Validator.isNotNull(String.valueOf(map.get("infoId")))) {
				PubInfoStatistics ps = new PubInfoStatistics();
				ps.setInfoId(Validator.generate());
				ps.setInfoUser(String.valueOf(map.get("createUser")));
				ps.setObjId(String.valueOf(map.get("infoId")));
				ps.setSortId(String.valueOf(vo.getParams("sortCode")));
				pvo.setObj(ps);
				pubInfoStatisticsManager.saveInfo(pvo);
			}
		}
		return mark;
	}

	public void setInfoReleaseManager(InfoReleaseManager infoReleaseManager) {
		InfoReleaseManager = infoReleaseManager;
	}

	public void setPubInfoStatisticsManager(PubInfoStatisticsManager pubInfoStatisticsManager) {
		this.pubInfoStatisticsManager = pubInfoStatisticsManager;
	}
}
